import { getInfoRequest, getPlatformSupportInfoRequest, getShopSupportInfoRequest } from '@/api/customer-support'

const customerSupport = {
  namespaced: true,
  state: {
    info: null,
    shopSupportInfo: undefined,
    platformSupportInfo: undefined,
  },

  getters: {},

  mutations: {
    SET_INFO: (state, info) => {
      state.info = info
    },

    SET_SHOP_SUPPORT_INFO: (state, shopSupportInfo) => {
      state.shopSupportInfo = shopSupportInfo
    },

    SET_PLATFORM_SUPPORT_INFO: (state, platformSupportInfo) => {
      state.platformSupportInfo = platformSupportInfo
    }
  },

  actions: {
    getInfoAction({ commit }, parameters) {
      return new Promise((resolve, reject) => {
        getInfoRequest(parameters)
          .then(response => {
            const info = response.result
            commit('SET_INFO', info)
            resolve(response)
          })
          .catch(error => {
            reject(error)
          })
      })
    },


    getShopSupportInfoAction({ commit }, parameters) {
      return new Promise((resolve, reject) => {
        getShopSupportInfoRequest(parameters)
          .then(response => {
            const info = response.result
            commit('SET_SHOP_SUPPORT_INFO', info)
            resolve(response)
          })
          .catch(error => {
            reject(error)
          })
      })
    },


    getPlatformSupportInfoAction({ commit }, parameters) {
      return new Promise((resolve, reject) => {
        getPlatformSupportInfoRequest(parameters)
          .then(response => {
            const info = response.result
            commit('SET_PLATFORM_SUPPORT_INFO', info)
            resolve(response)
          })
          .catch(error => {
            reject(error)
          })
      })
    }
  }
}

export default customerSupport
